#include "gameobjects.h"

gameObjects::gameObjects()
{
	this->x = 0;
	this->y = 0;
	this->height = 0;
	this->width = 0;
	this->radius = 0;
	this->solid = false;
	this->affectedByGravity = false;
	this->hurtsOnTouch = false;
	this->visible = false;
	this->hasScript = false;
	this->rotating = false;
	this->currentRotation = 0.0f;
	this->rotationSpeed = 0.20f;
	this->curRotationSpeed = 0.20f;
	this->rotationAngle = 0.0f;
	this->rotationMinAngle = 0.0f;
	this->rotationMaxAngle = 0.0f;
	this->luaLocation = "";
	this->gofile = "";
	this->objectCategory = "";
}

gameObjects::~gameObjects()
{

}

void gameObjects::printObjectVariables()
{
	printf("x: %d\n", this->x);
	printf("y: %d\n", this->y);
	printf("width: %d\n", this->width);
	printf("height: %d\n", this->height);
	printf("radius: %d\n", this->radius);
	if(solid){ printf("solid: true\n"); }else{ printf("solid: false\n"); }
	if(affectedByGravity){ printf("affectedByGravity: true\n"); }else{ printf("affectedByGravity: false\n"); }
	if(hurtsOnTouch){ printf("hurtsOnTouch: true\n"); }else{ printf("hurtsOnTouch: false\n"); }
	if(visible){ printf("visible: true\n"); }else{ printf("visible: false\n"); }
	if(hasScript){ printf("hasScript: true\n"); }else{ printf("hasScript: false\n"); }
	if(rotating){ printf("rotating: true\n"); }else{ printf("rotating: false\n"); }
	printf("rotationAngle: %f\n", this->rotationAngle);
	printf("rotationMinAngle: %f\n", this->rotationMinAngle);
	printf("rotationMaxAngle: %f\n", this->rotationMaxAngle);
	printf("IMGLocation: %s\n", this->imgLocation.c_str());
	printf("luaLocation: %s\n", this->luaLocation.c_str());
	printf("gofile: %s\n", this->gofile.c_str());
	printf("objectCategory: %s\n", this->objectCategory.c_str());
}

void gameObjects::init()
{
	// Load the Image and it's attributes
	this->image.loadFromFile(this->imgLocation);
	this->texture.loadFromImage(this->image);
	this->sprite.setTexture(this->texture);
			
	sf::Vector2u tmpSize = this->texture.getSize();
	this->width = tmpSize.x;
	this->height = tmpSize.y;

	this->sprite.setPosition(this->x, this->y);
}

void gameObjects::think()
{
	if(this->rotating)
	{
		if(curRotationSpeed > 0.00 )
		{
			currentRotation += 0.10;

			// Set Pivot
			this->sprite.setOrigin(this->width/2, this->height/2);
			this->sprite.rotate(curRotationSpeed);

			if(currentRotation >= rotationMaxAngle)
			{
				curRotationSpeed = -rotationSpeed;
			}
		}
		else
		{
			currentRotation -= 0.10;

			// Set Pivot
			this->sprite.setOrigin(this->width/2, this->height/2);
			this->sprite.rotate(curRotationSpeed);

			if(currentRotation <= rotationMinAngle)
			{
				curRotationSpeed = rotationSpeed;
			}
		}
	}
}